clear


set maxvar 10000
set matsize 4000
/*
****** Data cleaning (Done)
*Raw file from SIPP

use "C:\Users\Bobby W. Chung\Desktop\SIPPdata\pu2014w2.dta" 

keep if inrange(tage,18,64) & ejb1_scrnr==1 

drop if tehc_st=="61"

*Create hourly wage
generate long wage = (tjb1_annsal1)/4/12/40
drop if wage>100
drop if wage<5
gen lwage =log(wage)


* Drop female or hispanic or other race
drop if esex==2
drop if eorigin==1
keep if inlist(erace,1,2)

save "C:\Users\Bobby W. Chung\Desktop\SIPPdata\panel2014.dta" ,replace
clear

foreach y in 3 4{
	use "C:\Users\Bobby W. Chung\Desktop\SIPPdata\pu2014w`y'.dta" 

	keep if inrange(tage,18,64) & ejb1_scrnr==1 

	drop if tehc_st=="61"

	*Create hourly wage
	generate long wage = (tjb1_annsal1)/4/12/40
	drop if wage>100
	drop if wage<5
	gen lwage =log(wage)


	* Drop female or hispanic or other race
	drop if esex==2
	drop if eorigin==1
	keep if inlist(erace,1,2)
	
	append using "C:\Users\Bobby W. Chung\Desktop\SIPPdata\panel2014.dta"
	save "C:\Users\Bobby W. Chung\Desktop\SIPPdata\panel2014.dta" ,replace
clear
}
*/
*******

*Open Cleaned data
use "panel2014.dta" 


gen black=0
replace black=1 if erace==2

gen age2=tage*tage

gen union=0
replace union=1 if ejb1_union==1


*Create education dummy
generate hs =0
replace hs=1 if eeduc==39
generate somecollege =0
replace somecollege=1 if inrange(eeduc,40,42)
generate college=0
replace college=1 if eeduc ==43
generate postgrad=0
replace postgrad=1 if eeduc >43


*Create self-employment
generate self_emp=1
replace self_emp=0 if ejb1_clwrk>6

*Create gov't summy
generate govt=0
replace govt=1 if inrange(ejb1_clwrk,1,4)

*service worker?
destring tjb1_ind, replace
gen service=0
replace service=1 if inrange(tjb1_ind,6870,9290)

destring tjb1_occ, replace
destring tehc_st, replace
******************
gen license=0
replace license=1 if eprocert==1 & ewhocert1==1 & acert==1 & aprocert==1

gen cert=0
replace cert=1 if eprocert==1  & license==0

*gen lwage=log(tjb1_hourly1)

*su license

************** Redefine licensing by 50/50 rule
egen licensecheck=mean(license), by(tehc_st tjb1_occ)
replace license=0 if licensecheck<0.5
replace license=1 if licensecheck>=0.5
*/
*su license


*Merge with ban data
gen state_occ=string(tehc_st)+"-"+string(tjb1_occ) if license==1

merge m:1 state_occ using "mandatory_unique.dta", generate(_felonymerge)

drop if _felonymerge==2
replace permban=0 if _felonymerge==1
replace felony=0 if _felonymerge==1

rename permban Ban
label var Ban "Ban"

replace quality=100 if missing(quality)

***"permban" only contains permanent ban
***"felony" contains both temporary and permanent ban


local controls  tage age2 hs somecollege college postgrad union govt self_em service 
*quality


gen boxyes=0
replace boxyes=1 if inlist(tehc_st,6,8,9,11,15,25,27,35)

gen BTBban=Ban*boxyes
replace Ban=0 if BTBban==1
gen nonBTBban=Ban

foreach y in license BTBban nonBTBban{
	gen `y'_black=`y'*black
	label var `y'_black "`y'*black"
}

gen commuter=0
replace commuter=1 if rjb1_commtyp==8

su black if commuter==1
su black if commuter==1 & license==1
su black if commuter==1 & nonBTBban==1
su black if commuter==1 & BTBban==1


areg lwage black license license_black  BTBban* nonBTBban* cert `controls'  i.tehc_st i.monthcode [aw=wpfinwgt], vce(cluster tehc_st) absorb(tjb1_occ)
outreg2 using TableB5.tex, keep(black license license_black  BTBban* nonBTBban*) replace
areg lwage black license license_black  BTBban* nonBTBban* cert `controls'  i.tehc_st i.monthcode [aw=wpfinwgt] if commuter==0, vce(cluster tehc_st) absorb(tjb1_occ)
outreg2 using TableB5.tex, keep(black license license_black  BTBban* nonBTBban*) 
